/*
   Copyright (c) [Year] [name of copyright holder]
   [Software Name] is licensed under Mulan PSL v2.
   You can use this software according to the terms and conditions of the Mulan PSL v2. 
   You may obtain a copy of Mulan PSL v2 at:
            http://license.coscl.org.cn/MulanPSL2 
   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.  
   See the Mulan PSL v2 for more details.  
*/

#ifndef JIAJIA_FUNC_HPP
#define JIAJIA_FUNC_HPP

#include"jiajiastd.hpp"
#include"jjlog.hpp"

// 该文件是定义标准库函数，扩展函数，收录函数的
// 关于 jiajia 函数的格式:

namespace jiajia{

    class jjfunc{
    private:
        std::map<my::ustring, func_t> mFuncMap;
    public:

        func_t findFunc(const jjtoken & token){
            auto it = mFuncMap.find(token.getSrc());
            if(it != mFuncMap.end())
                return (*it).second;
            return nullptr;
        }

        func_t findFunc(const my::ustring & name){
            auto it = mFuncMap.find(name);
            if(it != mFuncMap.end())
                return (*it).second;
            return nullptr;
        }

        void insertFunc(const my::ustring & name, func_t f){
            mFuncMap[name] = f;
        }
    };

    static jjfunc func;

    namespace lib{

        msg_t print(value_t * arg, const size_t size, value_t * result){
            for(size_t i = 0; i < size; ++i){
                value_t & val = arg[i];
                if(val.getType() == value_t::STRINGTYPE)
                    log.out(val.getStr().toString());
                else{
                    std::string s;
                    val.toString(s);
                    log.out(s);
                }
            }
            return msg::success;
        }

        msg_t inputnum(value_t * arg, const size_t size, value_t * result){
            for(size_t i = 0; i < size; ++i){

            }
            return msg::success;
        }

        msg_t inputstr(value_t * arg, const size_t size, value_t * result){

            return msg::success;
        }

        msg_t randnum(value_t * arg, const size_t size, value_t * result){
        }

        void init_func(){
            func.insertFunc("打印", print);
            func.insertFunc("输入数字", inputnum);
            func.insertFunc("输入字符串", inputstr);
        }
    };
}

#endif
